/*
 * Copyright 2020 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.chenjianlink.android.alarmclock

import android.content.Context
import androidx.room.Room
import cn.chenjianlink.android.alarmclock.db.AppDatabase
//import com.example.jetcaster.data.CategoryStore
//import com.example.jetcaster.data.EpisodeStore
//import com.example.jetcaster.data.PodcastStore
//import com.example.jetcaster.data.PodcastsFetcher
//import com.example.jetcaster.data.PodcastsRepository
//import com.example.jetcaster.data.room.JetcasterDatabase
//import com.example.jetcaster.data.room.TransactionRunner
//import com.rometools.rome.io.SyndFeedInput
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import okhttp3.Cache
import okhttp3.OkHttpClient
//import okhttp3.logging.LoggingEventListener
import java.io.File

/**
 * A very simple global singleton dependency graph.
 *
 * For a real app, you would use something like Hilt/Dagger instead.
 * 一个非常简单的全局单例依赖关系图。
 *
 *对于一个真正的应用程序，你可以使用像刀柄/匕首这样的东西。
 */
object Graph {
    lateinit var okHttpClient: OkHttpClient

    lateinit var database: AppDatabase
        private set



    //val podcastRepository by lazy {
    //    PodcastsRepository(
    //        podcastsFetcher = podcastFetcher,
    //        podcastStore = podcastStore,
    //        episodeStore = episodeStore,
    //        categoryStore = categoryStore,
    //        transactionRunner = transactionRunner,
    //        mainDispatcher = mainDispatcher
    //    )
    //}
    //
    //private val podcastFetcher by lazy {
    //    PodcastsFetcher(
    //        okHttpClient = okHttpClient,
    //        syndFeedInput = syndFeedInput,
    //        ioDispatcher = ioDispatcher
    //    )
    //}
    //
    //val podcastStore by lazy {
    //    PodcastStore(
    //        podcastDao = database.podcastsDao(),
    //        podcastFollowedEntryDao = database.podcastFollowedEntryDao(),
    //        transactionRunner = transactionRunner
    //    )
    //}
    //
    //val episodeStore by lazy {
    //    EpisodeStore(
    //        episodesDao = database.episodesDao()
    //    )
    //}
    //
    //val categoryStore by lazy {
    //    CategoryStore(
    //        categoriesDao = database.categoriesDao(),
    //        categoryEntryDao = database.podcastCategoryEntryDao(),
    //        episodesDao = database.episodesDao(),
    //        podcastsDao = database.podcastsDao()
    //    )
    //}

    private val mainDispatcher: CoroutineDispatcher
        get() = Dispatchers.Main

    private val ioDispatcher: CoroutineDispatcher
        get() = Dispatchers.IO

   public fun provide(context: Context) {
        //okHttpClient = OkHttpClient.Builder()
        //    .cache(Cache(File(context.cacheDir, "http_cache"), (20 * 1024 * 1024).toLong()))
        //    .apply {
        //        if (BuildConfig.DEBUG) eventListenerFactory(LoggingEventListener.Factory())
        //    }
        //    .build()

        database= AppDatabase.getDatabase(context)
        //database = Room.databaseBuilder(context, JetcasterDatabase::class.java, "data.db")
        //    // This is not recommended for normal apps, but the goal of this sample isn't to
        //    // showcase all of Room.
        //这不建议用于普通应用程序，但本示例的目标不是
////展示整个房间。
        //    .fallbackToDestructiveMigration()
        //    .build()
    }
}
